/**------------------------------------------------------------
 *
 * Copyright © 2014 rubbervalley. All rights reserved.
 *
 * @Title: PlatStoreUploadfileController.java
 * @Package: com.rubbervalley.uyo.actions
 * @Description:企业-文件
 * @author: zhoulei
 * @date: 上午10:35:28
 * @version: V1.0
 * 
 * Update History:
 * 
 ------------------------------------------------------------*/
package com.rubbervalley.uyo.actions.administrator;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rubbervalley.framework.core.common.MessageUtil;
import com.rubbervalley.framework.core.common.ObjectMessages;
import com.rubbervalley.platform.business.PlatStoreUploadfileService;
import com.rubbervalley.platform.domain.PlatStoreUploadfile;

@Controller
@RequestMapping(value="/uyo")
public class PlatStoreUploadfileController {
    @Autowired
    private PlatStoreUploadfileService platStoreUploadfileService;

    @Autowired
    private MessageUtil messageUtil;

    private static final Logger logger = LoggerFactory.getLogger(PlatStoreUploadfileController.class);

    @RequestMapping(value="/platStoreUploadfiles",method = RequestMethod.GET)
    String platStoreUploadfiles(Map<String, Object> model) {
        logger.debug("logger");
    return "/uyo/platStoreUploadfile/platStoreUploadfiles.ftl";
    }

    @RequestMapping(value="/platStoreUploadfile/{id}",method = RequestMethod.GET)
    public String detail(Map<String, Object> model, @PathVariable("id") Integer id) {
        // TODO: 初始化 
     PlatStoreUploadfile    bean = platStoreUploadfileService.select(id);
    model.put("bean",bean);
    return "/uyo/platStoreUploadfile/detail.ftl";
    }

    public void validate(PlatStoreUploadfile platStoreUploadfile, Errors errors) {
        // TODO: 校验 
     //  ValidationUtils.rejectIfEmpty(errors, "name", "user.name.required", "name的内容不能为空");
//  errors.reject("system.resource.update.success");
//  errors.rejectValue("name", "名称不正确。");

    }

    @RequestMapping(value="/platStoreUploadfile/add",method = RequestMethod.GET)
    public String add(Map<String, Object> model) {
        // TODO: 初始化 
    return "/uyo/platStoreUploadfile/add.ftl";
    }

    @RequestMapping(value="/platStoreUploadfile/add",method = RequestMethod.POST)
    @ResponseBody
    public ObjectMessages add(Map<String, Object> model, PlatStoreUploadfile platStoreUploadfile, BindingResult result) {
        // TODO:修改代码 
     validate(platStoreUploadfile,result); // 数据校验 
if(!result.hasErrors()){ 
    // TODO:校验失败 
         return messageUtil.messages("platStoreUploadfile.add.error"); 
}else{ 
    this.platStoreUploadfileService.insert(platStoreUploadfile);
   // TODO:成功处理
         return messageUtil.messages("platStoreUploadfile.add.success"); 
}

    }

    @RequestMapping(value="/platStoreUploadfile/{id}/update",method = RequestMethod.GET)
    public String update(Map<String, Object> model, @PathVariable("id") Integer id) {
        // TODO: 初始化 
     PlatStoreUploadfile    bean = platStoreUploadfileService.select(id);
    model.put("bean",bean);
    return "/uyo/platStoreUploadfile/update.ftl";
    }

    @RequestMapping(value="/platStoreUploadfile/{id}/update",method = RequestMethod.POST)
    @ResponseBody
    public ObjectMessages update(Map<String, Object> model, PlatStoreUploadfile platStoreUploadfile, BindingResult result) {
        // TODO:修改代码 
     validate(platStoreUploadfile,result); // 数据校验 
if(result.hasErrors()){ 
    // TODO:校验失败 
         return messageUtil.messages("platStoreUploadfile.update.error"); 
}else{ 
    this.platStoreUploadfileService.update(platStoreUploadfile);
   // TODO:成功处理
         return messageUtil.messages("platStoreUploadfile.update.success"); 
}

    }

    @RequestMapping(value="/platStoreUploadfile/{id}/delete")
    @ResponseBody
    public ObjectMessages delete(Map<String, Object> model, @PathVariable("id") Integer id) {
        // TODO:代码 
         this.platStoreUploadfileService.delete(id);
 return messageUtil.messages("platStoreUploadfile.delete.success"); 

    }
}